package com.zhongkai.encryptRSA;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

public class EncryptRSAtest {

	/**
	 * 
	 * @author lengxue
	 * @date 13 Jul 2012 09:04:34
	 * @param args
	 * @note
	 */
	public static void main( String[] args ) throws Exception {
		EncryptRSA encryptRSA = new EncryptRSA( );
		String message = "郭德刚相声全集，使用RSA";
		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance( "RSA" );
		keyPairGenerator.initialize( 1024 );
		KeyPair keyPair = keyPairGenerator.generateKeyPair( );
		RSAPublicKey publicKey = (RSAPublicKey ) keyPair.getPublic( );
		RSAPrivateKey privateKey = ( RSAPrivateKey ) keyPair.getPrivate( );
		
		byte [] encontent = encryptRSA.Encrypt( publicKey, message.getBytes("UTF-8"));
		byte [] decontent = encryptRSA.Decrypt( privateKey, encontent );
		System.out.println("明文是:" + message);
		System.out.println("加密后:" + new String( encontent ,"UTF-8"));
		System.out.println("解密后：" + new String( decontent ));
	}

}
